<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      Array.prototype.myFilter = function (callback) {
        let arr = []
        for (let i = 0; i < this.length; i++) {
          //如果这个回调函数的结果为true 那么就添加到数组里面  
          if (callback(this[i], i, this)) {
            arr.push(this[i])
          }
          }
          //filter有返回值
        return arr
      }
      const arr1 = [2, 3, 4, 5]
      let arr2 = arr1.myFilter((item, i, arr) => {
        return item > 3
      })
      console.log(arr2)
    </script>
  </body>
</html>
